<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 15-5-18
 * Time: 上午9:34
 * 常态监控控制器
 */
namespace Factory\Controller;
use Mcit\Page;
class NormalcyController extends BaseController {

    public function index(){

        //2---厂商  3---运营商
        if(session("fac_type") == 2){
            if (session('fac_key')){
                $condition_str  = "b.ev_fac_code='".session('fac_key')."' and c.yy_user_id='".session('uid')."'";
                $condition_strs = "b.ev_fac_code='".session('fac_key')."' and a.yy_user_id='".session('uid')."'";
            }else{
                $condition_str  = "b.ev_fac_code='".session('fac_login_name')."'";
                $condition_strs = "b.ev_fac_code='".session('fac_login_name')."'";
            }
        }elseif(session("fac_type") == 3){
            if(session('pid') != 0){
                $operation  = "c.plant_attr=3 and c.yy_user_id='".session('uid')."'";
                $operations = "a.plant_attr=3 and a.yy_user_id='".session('uid')."'";
            }else{
                $yyuserid = M()->query("select id from ev_fac where id='".session('uid')."' OR pid='".session('uid')."'");
                foreach($yyuserid as $k=>$v){
                    $yyuserids .= $v['id'].",";
                }
                $yyuserids  = trim($yyuserids,',');
                $operation  = "c.plant_attr=3 and c.yy_user_id IN($yyuserids)";
                $operations = "a.plant_attr=3 and a.yy_user_id IN($yyuserids)";
            }
        }
        $oldtime   = I("oldtime");//前30天
        $tomonth   = I("month");//某月
        $key_link  = I("key_link");
        //前30天数据
        if(!empty($oldtime)){
            $begin     = date("Y-m-d",time()-30*86400);//30天前日期
            $nextmonth = date("Y-m-d",time());//今天日期
        }elseif(!empty($tomonth)){
            $begin     = date("Y-m-01",strtotime($tomonth));//某月的第一天
            $year1     = date("Y",strtotime($tomonth));
            $month1    = date("m",strtotime($tomonth));
            $nextmonth = date('Y-m-d', mktime(0, 0, 0, $month1 + 1, 1, $year1));//某月的下个月第一天
        }else{
            $year      = date("Y",time());
            $month     = date("m",time());
            $begin     = date('Y-m-01', strtotime(date("Y-m-d")));//当前月的第一天
//            $end       = date('Y-m-d', strtotime("$begin +1 month -1 day"));//当前月的最后一天
            $nextmonth = date('Y-m-d', mktime(0, 0, 0, $month + 1, 1, $year));//下个月的第一天
        }
        if(!empty($key_link)){
            $sql   = "select * from ev_heart_total a
                      left join ev_char b
                      on b.key_link = a.key_link
                      left join ev_plant c
                      on c.id = b.ev_plant_id
                      where a.currentTime >= '$begin' and a.currentTime < '$nextmonth'
                      and a.key_link like '$key_link%'
                      and {$condition_str} {$operation}
                      group by a.key_link";
        }else{
            $sql   = "select * from ev_heart_total a
                      left join ev_char b
                      on b.key_link = a.key_link
                      left join ev_plant c
                      on c.id = b.ev_plant_id
                      where a.currentTime >= '$begin' and a.currentTime < '$nextmonth'
                      and {$condition_str} {$operation}
                      group by a.key_link";
        }
        $count = count(M()->query($sql));
//        echo M()->getLastSql()."<br />";
//        P($count);die;
        vendor('Mcit.Sys.Page');
        $Page     = new Page($count, 5);
        $pageView = $Page->show();
        $this->assign('pageView', $pageView); //发送分页
        $nowPage = isset($_GET['page']) ? $_GET['page'] * 5 - 5 : 0;
        if(!empty($key_link)){
            $sql1 = "select a.key_link,c.location,c.name,b.evc_number from ev_heart_total a
            left join ev_char b on b.key_link=a.key_link
            left join ev_plant c on c.id=b.ev_plant_id
            where {$condition_str} {$operation}
            and a.currentTime >= '$begin' and a.currentTime < '$nextmonth'
            and a.key_link like '$key_link%'
            group by a.key_link
            limit $nowPage,".$Page->listRows;
        }else{
            $sql1 = "select a.key_link,c.location,c.name,b.evc_number from ev_heart_total a
            left join ev_char b on b.key_link=a.key_link
            left join ev_plant c on c.id=b.ev_plant_id
            where {$condition_str} {$operation}
            and a.currentTime >= '$begin' and a.currentTime < '$nextmonth'
            group by a.key_link
            limit $nowPage,".$Page->listRows;
        }
        $normalcy = M()->query($sql1);
//        echo M()->getLastSql()."<br />";
//        P($normalcy);
        foreach($normalcy as $k => $v){
            if(!empty($oldtime)){
                $normalcy[$k]['month'] = $begin."~".$nextmonth;
            }elseif(!empty($tomonth)){
                $normalcy[$k]['month'] = $begin."~".$nextmonth;
            }else{
                $normalcy[$k]['month'] = date("Y-m",time());
            }
            $region = strsToArray($v['location']);
            $normalcy[$k]['location_text'] = M("region")->where("code=".$region['2'])->getField("fullname");
            $sql2 = "select * from ev_heart_total where currentTime >= '$begin' and currentTime < '$nextmonth' and key_link = ".$v['key_link'];
            $normalcy[$k]['detail'] = M()->query($sql2);
            foreach($normalcy[$k]['detail'] as $key=>$val){
                $normalcy[$k]['detail'][$key]['day'] = date("d",strtotime($val['currentTime']));
                if($val['zero'] >= 150 && $val['one'] >= 150 && $val['two'] >= 150 && $val['three'] >= 150 && $val['four'] >= 150 && $val['five'] >= 150 && $val['six'] >= 150 && $val['seven'] >= 150 && $val['eight'] >= 150 && $val['nine'] >= 150 && $val['ten'] >= 150 && $val['eleven'] >= 150 && $val['thirteen'] >= 150 && $val['fourteen'] >= 150 && $val['fifteen'] >= 150 && $val['sixteen'] >= 150 && $val['seventeen'] >= 150 && $val['eiighteen'] >= 150 && $val['nineteen'] >= 150 && $val['twenty'] >= 150 && $val['twenty_one'] >= 150 && $val['twenty_two'] >= 150 && $val['twenty_three'] >= 150 && $val['twenty_four'] >= 150 && $val['twenty_five'] >= 150 && $val['twenty_six'] >= 150 && $val['twenty_seven'] >= 150 && $val['twenty_eight'] >= 150 && $val['twenty_nine'] >= 150 && $val['thirty'] >= 150 && $val['thirty_one'] >= 150 && $val['thirty_two'] >= 150 && $val['thirty_three'] >= 150 && $val['thirty_four'] >= 150 && $val['thirty_five'] >= 150 && $val['thirty_six'] >= 150 && $val['thirty_seven'] >= 150 && $val['thirty_eight'] >= 150 && $val['thirty_nine'] >= 150 && $val['forty'] >= 150 && $val['forty_one'] >= 150 && $val['forty_two'] >= 150 && $val['forty_three'] >= 150 && $val['forty_four'] >= 150 && $val['forty_five'] >= 150 && $val['forty_six'] >= 150 && $val['forty_seven'] >= 150 && $val['twelve'] >= 150 ){
                    $normalcy[$k]['detail'][$key]['colors'] = "btn-success";
                }elseif($val['zero'] < 150 && $val['zero'] >= 1 || $val['one'] < 150 && $val['one'] >= 1 || $val['two'] < 150 && $val['two'] >= 1 || $val['three'] < 150 && $val['three'] >= 1 || $val['four'] < 150 && $val['four'] >= 1 || $val['five'] < 150 && $val['five'] >= 1 || $val['six'] < 150 && $val['six'] >= 1 || $val['seven'] < 150 && $val['seven'] >= 1 || $val['eight'] < 150 && $val['eight'] >= 1 || $val['nine'] < 150 && $val['nine'] >= 1 || $val['ten'] < 150 && $val['ten'] >= 1 || $val['eleven'] < 150 && $val['eleven'] >= 1 || $val['twelve'] < 150 && $val['twelve'] >= 1 || $val['thirteen'] < 150 && $val['thirteen'] >= 1 || $val['fourteen'] < 150 && $val['fourteen'] >= 1 || $val['fifteen'] < 150 && $val['fifteen'] >= 1 || $val['sixteen'] < 150 && $val['sixteen'] >= 1 || $val['seventeen'] < 150 && $val['seventeen'] >= 1 || $val['eiighteen'] < 150 && $val['eiighteen'] >= 1 || $val['nineteen'] < 150 && $val['nineteen'] >= 1 || $val['twenty'] < 150 && $val['twenty'] >= 1 || $val['twenty_one'] < 150 && $val['twenty_one'] >= 1 || $val['twenty_two'] < 150 && $val['twenty_two'] >= 1 || $val['twenty_three'] < 150 && $val['twenty_three'] >= 1 || $val['twenty_four'] < 150 && $val['twenty_four'] >= 1 || $val['twenty_five'] < 150 && $val['twenty_five'] >= 1 || $val['twenty_six'] < 150 && $val['twenty_six'] >= 1 || $val['twenty_seven'] < 150 && $val['twenty_seven'] >= 1 || $val['twenty_eight'] < 150 && $val['twenty_eight'] >= 1 || $val['twenty_nine'] < 150 && $val['twenty_nine'] >= 1 || $val['thirty'] < 150 && $val['thirty'] >= 1 || $val['thirty_one'] < 150 && $val['thirty_one'] >= 1 || $val['thirty_two'] < 150 && $val['thirty_two'] >= 1 || $val['thirty_three'] < 150 && $val['thirty_three'] >= 1 || $val['thirty_four'] < 150 && $val['thirty_four'] >= 1 || $val['thirty_five'] < 150 && $val['thirty_five'] >= 1 || $val['thirty_six'] < 150 && $val['thirty_six'] >= 1 || $val['thirty_seven'] < 150 && $val['thirty_seven'] >= 1 || $val['thirty_eight'] < 150 && $val['thirty_eight'] >= 1 || $val['thirty_nine'] < 150 && $val['thirty_nine'] >= 1 || $val['forty'] < 150 && $val['forty'] >= 1 || $val['forty_one'] < 150 && $val['forty_one'] >= 1 || $val['forty_two'] < 150 && $val['forty_two'] >= 1 || $val['forty_three'] < 150 && $val['forty_three'] >= 1 || $val['forty_four'] < 150 && $val['forty_four'] >= 1 || $val['forty_five'] < 150 && $val['forty_five'] >= 1 || $val['forty_six'] < 150 && $val['forty_six'] >= 1 || $val['forty_seven'] < 150 && $val['forty_seven'] >= 1){
                    $normalcy[$k]['detail'][$key]['colors'] = "btn-warning";
                }else{
                    $normalcy[$k]['detail'][$key]['colors'] = "btn-danger";
                }
            }
        }
        if(!empty($_GET['location_t_1'])){
            if(I('location_s_1') == 110100 || I('location_s_1') == 120100 || I('location_s_1') == 310100 || I('location_s_1') == 500100){
                if(I('location_s_1') == I('location_t_1')-1){
                    $location = I('location_f_1').",".I('location_s_1');
                }else{
                    $location = I('location_f_1').",".I('location_s_1').",".I('location_t_1');
                }
            }else if(I('location_s_1') == I('location_t_1')-1){
                $location = I('location_f_1').",".I('location_s_1');
            }else{
                $location = I('location_f_1').",".I('location_s_1').",".I('location_t_1');
            }
            $year      = date("Y",time());
            $month     = date("m",time());
            $begin     = date('Y-m-01', strtotime(date("Y-m-d")));//当前月的第一天
            $nextmonth = date('Y-m-d', mktime(0, 0, 0, $month + 1, 1, $year));//下个月的第一天
            $sql5  = "select count(c.id),a.location,c.key_link from ev_plant a
                      left join ev_char b on b.ev_plant_id=a.id
                      left join ev_heart_total c on c.key_link=b.key_link
                      where {$condition_strs} {$operations}
                      and location like '%$location%' and c.currentTime >= '$begin'
                      and c.currentTime < '$nextmonth' group by c.key_link";
            $count = count(M()->query($sql5));
            $Page     = new Page($count, 5);
            $pageView = $Page->show();
            $this->assign('pageView', $pageView); //发送分页
            $nowPage = isset($_GET['page']) ? $_GET['page'] * 5 - 5 : 0;
            $sql6 = "select a.name,a.location,c.key_link,b.evc_number from ev_plant a
                     left join ev_char b on b.ev_plant_id=a.id
                     left join ev_heart_total c on c.key_link=b.key_link
                     where {$condition_strs} {$operations}
                     and location like '%$location%' and c.currentTime >= '$begin'
                     and c.currentTime < '$nextmonth'  group by c.key_link
                     limit $nowPage,".$Page->listRows;
            $normalcy = M()->query($sql6);
//            P($normalcy);
            foreach($normalcy as $k => $v){
                $normalcy[$k]['month'] = date("Y-m",time());
                $region = strsToArray($v['location']);
                $normalcy[$k]['location_text'] = M("region")->where("code=".$region['2'])->getField("fullname");
                $sql2 = "select * from ev_heart_total a
                         left join ev_char b
                         on b.key_link = a.key_link
                         where currentTime >= '$begin'
                         and currentTime < '$nextmonth'
                         and key_link = ".$v['key_link'];
                $normalcy[$k]['detail'] = M()->query($sql2);
                foreach($normalcy[$k]['detail'] as $key=>$val){
                    $normalcy[$k]['detail'][$key]['day'] = date("d",strtotime($val['currentTime']));
                    if($val['zero'] >= 150 && $val['one'] >= 150 && $val['two'] >= 150 && $val['three'] >= 150 && $val['four'] >= 150 && $val['five'] >= 150 && $val['six'] >= 150 && $val['seven'] >= 150 && $val['eight'] >= 150 && $val['nine'] >= 150 && $val['ten'] >= 150 && $val['eleven'] >= 150 && $val['thirteen'] >= 150 && $val['fourteen'] >= 150 && $val['fifteen'] >= 150 && $val['sixteen'] >= 150 && $val['seventeen'] >= 150 && $val['eiighteen'] >= 150 && $val['nineteen'] >= 150 && $val['twenty'] >= 150 && $val['twenty_one'] >= 150 && $val['twenty_two'] >= 150 && $val['twenty_three'] >= 150 && $val['twenty_four'] >= 150 && $val['twenty_five'] >= 150 && $val['twenty_six'] >= 150 && $val['twenty_seven'] >= 150 && $val['twenty_eight'] >= 150 && $val['twenty_nine'] >= 150 && $val['thirty'] >= 150 && $val['thirty_one'] >= 150 && $val['thirty_two'] >= 150 && $val['thirty_three'] >= 150 && $val['thirty_four'] >= 150 && $val['thirty_five'] >= 150 && $val['thirty_six'] >= 150 && $val['thirty_seven'] >= 150 && $val['thirty_eight'] >= 150 && $val['thirty_nine'] >= 150 && $val['forty'] >= 150 && $val['forty_one'] >= 150 && $val['forty_two'] >= 150 && $val['forty_three'] >= 150 && $val['forty_four'] >= 150 && $val['forty_five'] >= 150 && $val['forty_six'] >= 150 && $val['forty_seven'] >= 150 && $val['twelve'] >= 150 ){
                        $normalcy[$k]['detail'][$key]['colors'] = "btn-success";
                    }elseif($val['zero'] < 150 && $val['zero'] >= 1 || $val['one'] < 150 && $val['one'] >= 1 || $val['two'] < 150 && $val['two'] >= 1 || $val['three'] < 150 && $val['three'] >= 1 || $val['four'] < 150 && $val['four'] >= 1 || $val['five'] < 150 && $val['five'] >= 1 || $val['six'] < 150 && $val['six'] >= 1 || $val['seven'] < 150 && $val['seven'] >= 1 || $val['eight'] < 150 && $val['eight'] >= 1 || $val['nine'] < 150 && $val['nine'] >= 1 || $val['ten'] < 150 && $val['ten'] >= 1 || $val['eleven'] < 150 && $val['eleven'] >= 1 || $val['twelve'] < 150 && $val['twelve'] >= 1 || $val['thirteen'] < 150 && $val['thirteen'] >= 1 || $val['fourteen'] < 150 && $val['fourteen'] >= 1 || $val['fifteen'] < 150 && $val['fifteen'] >= 1 || $val['sixteen'] < 150 && $val['sixteen'] >= 1 || $val['seventeen'] < 150 && $val['seventeen'] >= 1 || $val['eiighteen'] < 150 && $val['eiighteen'] >= 1 || $val['nineteen'] < 150 && $val['nineteen'] >= 1 || $val['twenty'] < 150 && $val['twenty'] >= 1 || $val['twenty_one'] < 150 && $val['twenty_one'] >= 1 || $val['twenty_two'] < 150 && $val['twenty_two'] >= 1 || $val['twenty_three'] < 150 && $val['twenty_three'] >= 1 || $val['twenty_four'] < 150 && $val['twenty_four'] >= 1 || $val['twenty_five'] < 150 && $val['twenty_five'] >= 1 || $val['twenty_six'] < 150 && $val['twenty_six'] >= 1 || $val['twenty_seven'] < 150 && $val['twenty_seven'] >= 1 || $val['twenty_eight'] < 150 && $val['twenty_eight'] >= 1 || $val['twenty_nine'] < 150 && $val['twenty_nine'] >= 1 || $val['thirty'] < 150 && $val['thirty'] >= 1 || $val['thirty_one'] < 150 && $val['thirty_one'] >= 1 || $val['thirty_two'] < 150 && $val['thirty_two'] >= 1 || $val['thirty_three'] < 150 && $val['thirty_three'] >= 1 || $val['thirty_four'] < 150 && $val['thirty_four'] >= 1 || $val['thirty_five'] < 150 && $val['thirty_five'] >= 1 || $val['thirty_six'] < 150 && $val['thirty_six'] >= 1 || $val['thirty_seven'] < 150 && $val['thirty_seven'] >= 1 || $val['thirty_eight'] < 150 && $val['thirty_eight'] >= 1 || $val['thirty_nine'] < 150 && $val['thirty_nine'] >= 1 || $val['forty'] < 150 && $val['forty'] >= 1 || $val['forty_one'] < 150 && $val['forty_one'] >= 1 || $val['forty_two'] < 150 && $val['forty_two'] >= 1 || $val['forty_three'] < 150 && $val['forty_three'] >= 1 || $val['forty_four'] < 150 && $val['forty_four'] >= 1 || $val['forty_five'] < 150 && $val['forty_five'] >= 1 || $val['forty_six'] < 150 && $val['forty_six'] >= 1 || $val['forty_seven'] < 150 && $val['forty_seven'] >= 1){
                        $normalcy[$k]['detail'][$key]['colors'] = "btn-warning";
                    }else{
                        $normalcy[$k]['detail'][$key]['colors'] = "btn-danger";
                    }
                }
            }
        }
        $this->normalcy  = $normalcy;
        $this->china     = D("Admin/Region")->getChinaArea();
        $this->display();
    }

    //事件当天数据
    public function todays(){
        $map['currentTime'] = I("today");
        $map['key_link']    = I("key_link");
        $heart = M("heart_total")->where($map)->find();
        if($heart['zero'] >= 150){
            $variable = "btn-success";
        }else if($heart['zero'] < 150 && $heart['zero'] >= 1){
            $variable = "btn-warning";
        }else if($heart['zero'] < 1){
            $variable = "btn-danger";
        }
        if($heart['one'] >= 150){
            $variable1 = "btn-success";
        }else if($heart['one'] < 150 && $heart['one'] >= 1){
            $variable1 = "btn-warning";
        }else if($heart['one'] < 1){
            $variable1 = "btn-danger";
        }
        if($heart['two'] >= 150){
            $variable2 = "btn-success";
        }else if($heart['two'] < 150 && $heart['two'] >= 1){
            $variable2 = "btn-warning";
        }else if($heart['two'] < 1){
            $variable2 = "btn-danger";
        }
        if($heart['three'] >= 150){
            $variable3 = "btn-success";
        }else if($heart['three'] < 150 && $heart['three'] >= 1){
            $variable3 = "btn-warning";
        }else if($heart['three'] < 1){
            $variable3 = "btn-danger";
        }
        if($heart['four'] >= 150){
            $variable4 = "btn-success";
        }else if($heart['four'] < 150 && $heart['four'] >= 1){
            $variable4 = "btn-warning";
        }else if($heart['four'] < 1){
            $variable4 = "btn-danger";
        }
        if($heart['five'] >= 150){
            $variable5 = "btn-success";
        }else if($heart['five'] < 150 && $heart['five'] >= 1){
            $variable5 = "btn-warning";
        }else if($heart['five'] < 1){
            $variable5 = "btn-danger";
        }
        if($heart['six'] >= 150){
            $variable6 = "btn-success";
        }else if($heart['six'] < 150 && $heart['six'] >= 1){
            $variable6 = "btn-warning";
        }else if($heart['six'] < 1){
            $variable6 = "btn-danger";
        }
        if($heart['seven'] >= 150){
            $variable7 = "btn-success";
        }else if($heart['seven'] < 150 && $heart['seven'] >= 1){
            $variable7 = "btn-warning";
        }else if($heart['seven'] < 1){
            $variable7 = "btn-danger";
        }
        if($heart['eight'] >= 150){
            $variable8 = "btn-success";
        }else if($heart['eight'] < 150 && $heart['eight'] >= 1){
            $variable8 = "btn-warning";
        }else if($heart['eight'] < 1){
            $variable8 = "btn-danger";
        }
        if($heart['nine'] >= 150){
            $variable9 = "btn-success";
        }else if($heart['nine'] < 150 && $heart['nine'] >= 1){
            $variable9 = "btn-warning";
        }else if($heart['nine'] < 1){
            $variable9 = "btn-danger";
        }
        if($heart['ten'] >= 150){
            $variable10 = "btn-success";
        }else if($heart['ten'] < 150 && $heart['ten'] >= 1){
            $variable10 = "btn-warning";
        }else if($heart['ten'] < 1){
            $variable10 = "btn-danger";
        }
        if($heart['eleven'] >= 150){
            $variable11 = "btn-success";
        }else if($heart['eleven'] < 150 && $heart['eleven'] >= 1){
            $variable11 = "btn-warning";
        }else if($heart['eleven'] < 1){
            $variable11 = "btn-danger";
        }
        if($heart['twelve'] >= 150){
            $variable12 = "btn-success";
        }else if($heart['twelve'] < 150 && $heart['twelve'] >= 1){
            $variable12 = "btn-warning";
        }else if($heart['twelve'] < 1){
            $variable12 = "btn-danger";
        }
        if($heart['thirteen'] >= 150){
            $variable13 = "btn-success";
        }else if($heart['thirteen'] < 150 && $heart['thirteen'] >= 1){
            $variable13 = "btn-warning";
        }else if($heart['thirteen'] < 1){
            $variable13 = "btn-danger";
        }
        if($heart['fourteen'] >= 150){
            $variable14 = "btn-success";
        }else if($heart['fourteen'] < 150 && $heart['fourteen'] >= 1){
            $variable14 = "btn-warning";
        }else if($heart['fourteen'] < 1){
            $variable14 = "btn-danger";
        }
        if($heart['fifteen'] >= 150){
            $variable15 = "btn-success";
        }else if($heart['fifteen'] < 150 && $heart['fifteen'] >= 1){
            $variable15 = "btn-warning";
        }else if($heart['fifteen'] < 1){
            $variable15 = "btn-danger";
        }
        if($heart['sixteen'] >= 150){
            $variable16 = "btn-success";
        }else if($heart['sixteen'] < 150 && $heart['sixteen'] >= 1){
            $variable16 = "btn-warning";
        }else if($heart['sixteen'] < 1){
            $variable16 = "btn-danger";
        }
        if($heart['seventeen'] >= 150){
            $variable17 = "btn-success";
        }else if($heart['seventeen'] < 150 && $heart['seventeen'] >= 1){
            $variable17 = "btn-warning";
        }else if($heart['seventeen'] < 1){
            $variable17 = "btn-danger";
        }
        if($heart['eiighteen'] >= 150){
            $variable18 = "btn-success";
        }else if($heart['eiighteen'] < 150 && $heart['eiighteen'] >= 1){
            $variable18 = "btn-warning";
        }else if($heart['eiighteen'] < 1){
            $variable18 = "btn-danger";
        }
        if($heart['nineteen'] >= 150){
            $variable19 = "btn-success";
        }else if($heart['nineteen'] < 150 && $heart['nineteen'] >= 1){
            $variable19 = "btn-warning";
        }else if($heart['nineteen'] < 1){
            $variable19 = "btn-danger";
        }
        if($heart['twenty'] >= 150){
            $variable20 = "btn-success";
        }else if($heart['twenty'] < 150 && $heart['twenty'] >= 1){
            $variable20 = "btn-warning";
        }else if($heart['twenty'] < 1){
            $variable20 = "btn-danger";
        }
        if($heart['twenty_one'] >= 150){
            $variable21 = "btn-success";
        }else if($heart['twenty_one'] < 150 && $heart['twenty_one'] >= 1){
            $variable21 = "btn-warning";
        }else if($heart['twenty_one'] < 1){
            $variable21 = "btn-danger";
        }
        if($heart['twenty_two'] >= 150){
            $variable22 = "btn-success";
        }else if($heart['twenty_two'] < 150 && $heart['twenty_two'] >= 1){
            $variable22 = "btn-warning";
        }else if($heart['twenty_two'] < 1){
            $variable22 = "btn-danger";
        }
        if($heart['twenty_three'] >= 150){
            $variable23 = "btn-success";
        }else if($heart['twenty_three'] < 150 && $heart['twenty_three'] >= 1){
            $variable23 = "btn-warning";
        }else if($heart['twenty_three'] < 1){
            $variable23 = "btn-danger";
        }
        if($heart['twenty_four'] >= 150){
            $variable24 = "btn-success";
        }else if($heart['twenty_four'] < 150 && $heart['twenty_four'] >= 1){
            $variable24 = "btn-warning";
        }else if($heart['twenty_four'] < 1){
            $variable24 = "btn-danger";
        }
        if($heart['twenty_five'] >= 150){
            $variable25 = "btn-success";
        }else if($heart['twenty_five'] < 150 && $heart['twenty_five'] >= 1){
            $variable25 = "btn-warning";
        }else if($heart['twenty_five'] < 1){
            $variable25 = "btn-danger";
        }
        if($heart['twenty_six'] >= 150){
            $variable26 = "btn-success";
        }else if($heart['twenty_six'] < 150 && $heart['twenty_six'] >= 1){
            $variable26 = "btn-warning";
        }else if($heart['twenty_six'] < 1){
            $variable26 = "btn-danger";
        }
        if($heart['twenty_seven'] >= 150){
            $variable27 = "btn-success";
        }else if($heart['twenty_seven'] < 150 && $heart['twenty_seven'] >= 1){
            $variable27 = "btn-warning";
        }else if($heart['twenty_seven'] < 1){
            $variable27 = "btn-danger";
        }
        if($heart['twenty_eight'] >= 150){
            $variable28 = "btn-success";
        }else if($heart['twenty_eight'] < 150 && $heart['twenty_eight'] >= 1){
            $variable28 = "btn-warning";
        }else if($heart['twenty_eight'] < 1){
            $variable28 = "btn-danger";
        }
        if($heart['twenty_nine'] >= 150){
            $variable29 = "btn-success";
        }else if($heart['twenty_nine'] < 150 && $heart['twenty_nine'] >= 1){
            $variable29 = "btn-warning";
        }else if($heart['twenty_nine'] < 1){
            $variable29 = "btn-danger";
        }
        if($heart['thirty'] >= 150){
            $variable30 = "btn-success";
        }else if($heart['thirty'] < 150 && $heart['thirty'] >= 1){
            $variable30 = "btn-warning";
        }else if($heart['thirty'] < 1){
            $variable30 = "btn-danger";
        }
        if($heart['thirty_one'] >= 150){
            $variable31 = "btn-success";
        }else if($heart['thirty_one'] < 150 && $heart['thirty_one'] >= 1){
            $variable31 = "btn-warning";
        }else if($heart['thirty_one'] < 1){
            $variable31 = "btn-danger";
        }
        if($heart['thirty_two'] >= 150){
            $variable32 = "btn-success";
        }else if($heart['thirty_two'] < 150 && $heart['thirty_two'] >= 1){
            $variable32 = "btn-warning";
        }else if($heart['thirty_two'] < 1){
            $variable32 = "btn-danger";
        }
        if($heart['thirty_three'] >= 150){
            $variable33 = "btn-success";
        }else if($heart['thirty_three'] < 150 && $heart['thirty_three'] >= 1){
            $variable33 = "btn-warning";
        }else if($heart['thirty_three'] < 1){
            $variable33 = "btn-danger";
        }
        if($heart['thirty_four'] >= 150){
            $variable34 = "btn-success";
        }else if($heart['thirty_four'] < 150 && $heart['thirty_four'] >= 1){
            $variable34 = "btn-warning";
        }else if($heart['thirty_four'] < 1){
            $variable34 = "btn-danger";
        }
        if($heart['thirty_five'] >= 150){
            $variable35 = "btn-success";
        }else if($heart['thirty_five'] < 150 && $heart['thirty_five'] >= 1){
            $variable35 = "btn-warning";
        }else if($heart['thirty_five'] < 1){
            $variable35 = "btn-danger";
        }
        if($heart['thirty_six'] >= 150){
            $variable36 = "btn-success";
        }else if($heart['thirty_six'] < 150 && $heart['thirty_six'] >= 1){
            $variable36 = "btn-warning";
        }else if($heart['thirty_six'] < 1){
            $variable36 = "btn-danger";
        }
        if($heart['thirty_seven'] >= 150){
            $variable37 = "btn-success";
        }else if($heart['thirty_seven'] < 150 && $heart['thirty_seven'] >= 1){
            $variable37 = "btn-warning";
        }else if($heart['thirty_seven'] < 1){
            $variable37 = "btn-danger";
        }
        if($heart['thirty_eight'] >= 150){
            $variable38 = "btn-success";
        }else if($heart['thirty_eight'] < 150 && $heart['thirty_eight'] >= 1){
            $variable38 = "btn-warning";
        }else if($heart['thirty_eight'] < 1){
            $variable38 = "btn-danger";
        }
        if($heart['thirty_nine'] >= 150){
            $variable39 = "btn-success";
        }else if($heart['thirty_nine'] < 150 && $heart['thirty_nine'] >= 1){
            $variable39 = "btn-warning";
        }else if($heart['thirty_nine'] < 1){
            $variable39 = "btn-danger";
        }
        if($heart['forty'] >= 150){
            $variable40 = "btn-success";
        }else if($heart['forty'] < 150 && $heart['forty'] >= 1){
            $variable40 = "btn-warning";
        }else if($heart['forty'] < 1){
            $variable40 = "btn-danger";
        }
        if($heart['forty_one'] >= 150){
            $variable41 = "btn-success";
        }else if($heart['forty_one'] < 150 && $heart['forty_one'] >= 1){
            $variable41 = "btn-warning";
        }else if($heart['forty_one'] < 1){
            $variable41 = "btn-danger";
        }
        if($heart['forty_two'] >= 150){
            $variable42 = "btn-success";
        }else if($heart['forty_two'] < 150 && $heart['forty_two'] >= 1){
            $variable42 = "btn-warning";
        }else if($heart['forty_two'] < 1){
            $variable42 = "btn-danger";
        }
        if($heart['forty_three'] >= 150){
            $variable43 = "btn-success";
        }else if($heart['forty_three'] < 150 && $heart['forty_three'] >= 1){
            $variable43 = "btn-warning";
        }else if($heart['forty_three'] < 1){
            $variable43 = "btn-danger";
        }
        if($heart['forty_four'] >= 150){
            $variable44 = "btn-success";
        }else if($heart['forty_four'] < 150 && $heart['forty_four'] >= 1){
            $variable44 = "btn-warning";
        }else if($heart['forty_four'] < 1){
            $variable44 = "btn-danger";
        }
        if($heart['forty_five'] >= 150){
            $variable45 = "btn-success";
        }else if($heart['forty_five'] < 150 && $heart['forty_five'] >= 1){
            $variable45 = "btn-warning";
        }else if($heart['forty_five'] < 1){
            $variable45 = "btn-danger";
        }
        if($heart['forty_six'] >= 150){
            $variable46 = "btn-success";
        }else if($heart['forty_six'] < 150 && $heart['forty_six'] >= 1){
            $variable46 = "btn-warning";
        }else if($heart['forty_six'] < 1){
            $variable46 = "btn-danger";
        }
        if($heart['forty_seven'] >= 150){
            $variable47 = "btn-success";
        }else if($heart['forty_seven'] < 150 && $heart['forty_seven'] >= 1){
            $variable47 = "btn-warning";
        }else if($heart['forty_seven'] < 1){
            $variable47 = "btn-danger";
        }

        $str = '<p>'.$heart["currentTime"].'</p>
                <input type="hidden" class="keylink" value="'.$_GET['key_link'].'">
                <button type="button" class="btn btn-sm '.$variable.'">00:00<br/>'.$heart["zero"].'</button>
                <button type="button" class="btn btn-sm '.$variable1.'">00:30<br/>'.$heart["one"].'</button>
                <button type="button" class="btn btn-sm '.$variable2.'">01:00<br/>'.$heart["two"].'</button>
                <button type="button" class="btn btn-sm '.$variable3.'">01:30<br/>'.$heart["three"].'</button>
                <button type="button" class="btn btn-sm '.$variable4.'">02:00<br/>'.$heart["four"].'</button>
                <button type="button" class="btn btn-sm '.$variable5.'">02:30<br/>'.$heart["five"].'</button>
                <button type="button" class="btn btn-sm '.$variable6.'">03:00<br/>'.$heart["six"].'</button>
                <button type="button" class="btn btn-sm '.$variable7.'">03:30<br/>'.$heart["seven"].'</button><br/><br/>
                <button type="button" class="btn btn-sm '.$variable8.'">04:00<br/>'.$heart["eight"].'</button>
                <button type="button" class="btn btn-sm '.$variable9.'">04:30<br/>'.$heart["nine"].'</button>
                <button type="button" class="btn btn-sm '.$variable10.'">05:00<br/>'.$heart["ten"].'</button>
                <button type="button" class="btn btn-sm '.$variable11.'">05:30<br/>'.$heart["eleven"].'</button>
                <button type="button" class="btn btn-sm '.$variable12.'">06:00<br/>'.$heart["twelve"].'</button>
                <button type="button" class="btn btn-sm '.$variable13.'">06:30<br/>'.$heart["thirteen"].'</button>
                <button type="button" class="btn btn-sm '.$variable14.'">07:00<br/>'.$heart["fourteen"].'</button>
                <button type="button" class="btn btn-sm '.$variable15.'">07:30<br/>'.$heart["fifteen"].'</button><br/><br/>
                <button type="button" class="btn btn-sm '.$variable16.'">08:00<br/>'.$heart["sixteen"].'</button>
                <button type="button" class="btn btn-sm '.$variable17.'">08:30<br/>'.$heart["seventeen"].'</button>
                <button type="button" class="btn btn-sm '.$variable18.'">09:00<br/>'.$heart["eiighteen"].'</button>
                <button type="button" class="btn btn-sm '.$variable19.'">09:30<br/>'.$heart["nineteen"].'</button>
                <button type="button" class="btn btn-sm '.$variable20.'">10:00<br/>'.$heart["twenty"].'</button>
                <button type="button" class="btn btn-sm '.$variable21.'">10:30<br/>'.$heart["twenty_one"].'</button>
                <button type="button" class="btn btn-sm '.$variable22.'">11:00<br/>'.$heart["twenty_two"].'</button>
                <button type="button" class="btn btn-sm '.$variable23.'">11:30<br/>'.$heart["twenty_three"].'</button><br/><br/>
                <button type="button" class="btn btn-sm '.$variable24.'">12:00<br/>'.$heart["twenty_four"].'</button>
                <button type="button" class="btn btn-sm '.$variable25.'">12:30<br/>'.$heart["twenty_five"].'</button>
                <button type="button" class="btn btn-sm '.$variable26.'">13:00<br/>'.$heart["twenty_six"].'</button>
                <button type="button" class="btn btn-sm '.$variable27.'">13:30<br/>'.$heart["twenty_seven"].'</button>
                <button type="button" class="btn btn-sm '.$variable28.'">14:00<br/>'.$heart["twenty_eight"].'</button>
                <button type="button" class="btn btn-sm '.$variable29.'">14:30<br/>'.$heart["twenty_nine"].'</button>
                <button type="button" class="btn btn-sm '.$variable30.'">15:00<br/>'.$heart["thirty"].'</button>
                <button type="button" class="btn btn-sm '.$variable31.'">15:30<br/>'.$heart["thirty_one"].'</button><br/><br/>
                <button type="button" class="btn btn-sm '.$variable32.'">16:00<br/>'.$heart["thirty_two"].'</button>
                <button type="button" class="btn btn-sm '.$variable33.'">16:30<br/>'.$heart["thirty_three"].'</button>
                <button type="button" class="btn btn-sm '.$variable34.'">17:00<br/>'.$heart["thirty_four"].'</button>
                <button type="button" class="btn btn-sm '.$variable35.'">17:30<br/>'.$heart["thirty_five"].'</button>
                <button type="button" class="btn btn-sm '.$variable36.'">18:00<br/>'.$heart["thirty_six"].'</button>
                <button type="button" class="btn btn-sm '.$variable37.'">18:30<br/>'.$heart["thirty_seven"].'</button>
                <button type="button" class="btn btn-sm '.$variable38.'">19:00<br/>'.$heart["thirty_eight"].'</button>
                <button type="button" class="btn btn-sm '.$variable39.'">19:30<br/>'.$heart["thirty_nine"].'</button><br/><br/>
                <button type="button" class="btn btn-sm '.$variable40.'">20:00<br/>'.$heart["forty"].'</button>
                <button type="button" class="btn btn-sm '.$variable41.'">20:30<br/>'.$heart["forty_one"].'</button>
                <button type="button" class="btn btn-sm '.$variable42.'">21:00<br/>'.$heart["forty_two"].'</button>
                <button type="button" class="btn btn-sm '.$variable43.'">21:30<br/>'.$heart["forty_three"].'</button>
                <button type="button" class="btn btn-sm '.$variable44.'">22:00<br/>'.$heart["forty_four"].'</button>
                <button type="button" class="btn btn-sm '.$variable45.'">22:30<br/>'.$heart["forty_five"].'</button>
                <button type="button" class="btn btn-sm '.$variable46.'">23:00<br/>'.$heart["forty_six"].'</button>
                <button type="button" class="btn btn-sm '.$variable47.'">23:30<br/>'.$heart["forty_seven"].'</button>
        ';
        echo $str;
        exit;
    }
}